package com.yantong.pojo.wxtemplate;

import com.yantong.pojo.TemplateParam;
import lombok.Data;

import java.util.List;

/**
 * 微信发送消息
 * 参考api : https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Service_Center_messages.html#%E5%AE%A2%E6%9C%8D%E6%8E%A5%E5%8F%A3-%E5%8F%91%E6%B6%88%E6%81%AF
 * @author
 */
@Data
public class WxSendTextNews {

	/** 接收者openid  */
	private String touser;
	/** 文本消息 */
	private String text;
	/** 文本消息 */
	private String title;
	/** 文本消息 */
	private String description;
	/** 文本消息 */
	private String url;
	/** 文本消息 */
	private String picUrl;


	/**
	 * 发送文本消息
	 * @return
	 */
	public String toTextJSON() {
	    StringBuffer buffer = new StringBuffer();  
	    buffer.append("{");  
	    buffer.append(String.format("\"touser\":\"%s\"", this.touser)).append(",");  
	    buffer.append(String.format("\"msgtype\":\"%s\"", "text")).append(",");
	    buffer.append("\"text\"");
	    buffer.append(String.format(": {\"content\":\"%s\"}", this.text));
		buffer.append("}");
	    return buffer.toString();
	    }


	/**
	 * 发送图文消息
	 * @return
	 */
	public String toNewsJSON() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("{");
		buffer.append(String.format("\"touser\":\"%s\"", this.touser)).append(",");
		buffer.append(String.format("\"msgtype\":\"%s\"", "news")).append(",");
		buffer.append("\"news\":{\"articles\"");

		buffer.append(String.format(": [{\"title\":\"%s\"", this.title));
		buffer.append(String.format("\"description\":\"%s\"", this.description));
		buffer.append(String.format("\"url\":\"%s\"", this.url));
		buffer.append(String.format("\"picurl\":\"%s\"", this.picUrl));

		buffer.append("}]}}");
		return buffer.toString();
	}

}
